package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2022-12-28
 * Time: 16:09
 */
class MyRunnable implements Runnable {

    @Override
    public void run() {
        while (true){
            System.out.println("hello thread!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        //在这样写是为了把创建线程和执行线程里面的操作分开，解耦合
        MyRunnable myRunnable=new MyRunnable();
        Thread t=new Thread(myRunnable);
        t.start();

        while(true)
        {
            System.out.println("hello main!");
            Thread.sleep(1000);
        }
    }
}
